package pl.edu.pk.mech.kkbus.repository;

import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_NEW;
import static pl.edu.pk.mech.kkbus.staticstrings.NewProperty.NEW_CONTENT;
import static pl.edu.pk.mech.kkbus.staticstrings.NewProperty.NEW_DATE;
import static pl.edu.pk.mech.kkbus.staticstrings.NewProperty.NEW_TITLE;

import java.util.ArrayList;
import java.util.List;

import pl.edu.pk.mech.kkbus.datastore.common.SynchronizeCommon;
import pl.edu.pk.mech.kkbus.model.New;
import pl.edu.pk.mech.kkbus.model.Pojo;

import com.google.appengine.api.datastore.Entity;

public class NewDAO extends BaseDAO{
	
	  public List<New> getAllNews() {
		  List<New> temp = new ArrayList<New>();
		  Iterable<Entity> entityList = SynchronizeCommon.listEntities(NAME_ENTITY_NEW, null, null);
		  for (Entity entity : entityList) {
			  temp.add(new New(entity));
		  }
		  return temp;
	  }

	@Override
	public void fillProperty(Pojo pojo, Entity entity) {
		  New news = (New)pojo;
		  entity.setProperty(NEW_TITLE, news.getTitle());
		  entity.setProperty(NEW_CONTENT, news.getContent());
		  entity.setProperty(NEW_DATE, news.getDate());
	}
}
